﻿/*----------------------------------------------------------------
// Copyright (C) 2009 
// 版权所有。 
//
// 文件名：
// 文件功能描述：系统日志信息统计
//
//
// 创建标识：
// 程序作者：翟允锋
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using System.Threading;
using EQT.Model;
using Wuqi.Webdiyer;

public partial class ActLog : System.Web.UI.Page
{
    private static readonly Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger();
    private DaActLog daLog = DevFuture.Common.WorkContext.AppCtx.GetObject("DaActLog") as DaActLog;
    private DaDept dalDept = DevFuture.Common.WorkContext.AppCtx.GetObject("DaDept") as DaDept;
    private DaTuser dalUser = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTuser") as DaTuser;
    private UserContext context;
    private Boolean isClick = true;

    protected void Page_Load(object sender, EventArgs e)
    {

        context = Session["USER_CONTEXT"] as UserContext;

        OperationResult.Text = "";
        divResult.Visible = false;

        if (!IsPostBack)
        {
            DataSet dsDept = dalDept.Query(string.Empty);
            Utility.BindDataSet2Combox(dsDept, DDLdept, "Dept_Name", "Dept_ID");
            DDLdept.Items.Insert(0, new ListItem("", ""));
            this.DDLdept_SelectedIndexChanged(null, null);
            AspNetPager.PageSize = 15;
            this.BtnQuery_Click(null, null);
        }
    }

    protected void BtnQuery_Click(object sender, EventArgs e)
    {

        int pagecount = 0;
        string strCondition = "where 1=1 ";
        if (isClick)
        {
            AspNetPager.CurrentPageIndex = 0;
        }
        isClick = true;
        if (!string.IsNullOrEmpty(DDLdept.SelectedValue))
        {
            strCondition = strCondition + "and  Dept_ID='" + DDLdept.SelectedValue + "'";
        }
        //else
        //{
        //    strCondition = strCondition + "and  Dept_ID is null ";
        //}
        if (!string.IsNullOrEmpty(DdlUserID.SelectedValue))
        {
            strCondition = strCondition + "and  UID='" + DdlUserID.SelectedValue + "'";
        }
        //strCondition = strCondition + "and  YEARMONTH='" + DateTime.Now.Year.ToString()+DdlMonth.SelectedValue+ "'";
        DataSet dsRecords = daLog.GetActLogRecords(strCondition, AspNetPager.PageSize, AspNetPager.CurrentPageIndex - 1, out pagecount);
        this.GridView.DataSource = dsRecords;

        GridView.DataBind();

        //if (dsRecords.Tables[0].Rows.Count > 0)
        //{
        //    int days = DateTime.DaysInMonth(DateTime.Now.Year, int.Parse(DdlMonth.SelectedValue));

        //    for (int i = 4; i < 35; i++)
        //    {
        //        GridView.HeaderRow.Cells[i].Text = int.Parse(DdlMonth.SelectedValue).ToString() + "月" + Convert.ToString(i - 3) + "日<br/>" +
        //            ServerValidate.GetWeekDay(DateTime.Now.Year.ToString() + "-" + int.Parse(DdlMonth.SelectedValue).ToString() + "-" + Convert.ToString(i - 3));
        //        GridView.HeaderRow.Cells[i].HorizontalAlign = HorizontalAlign.Center;
        //        GridView.HeaderRow.Cells[i].Width = 60;
        //        GridView.HeaderRow.Cells[i].ForeColor = System.Drawing.Color.BlueViolet;
        //    }

        //    for (int i = 31; i > days; i--)
        //    {
        //        GridView.Columns[3 + i].Visible = false;
        //    }


        //    GridView.Width = 2400;
        //}
        AspNetPager.RecordCount = pagecount;
    }

    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        isClick = false;
        this.BtnQuery_Click(null, null);
    }

    protected void DDLdept_SelectedIndexChanged(object sender, EventArgs e)
    {
        DdlUserID.Items.Clear();
        DataSet dsUser = dalUser.GetUser_Emp_Info(DDLdept.SelectedValue);

        Utility.BindDataSet2Combox(dsUser, DdlUserID, "Display_Name", "UID");
        DdlUserID.Items.Insert(0, new ListItem("", ""));
    }
}
